﻿@model AvaliacaoOnline.Data.Usuario

@{
    ViewBag.Title = "Avaliação Online - Cadastro de usuário";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section head{
@if(!String.IsNullOrWhiteSpace(ViewData["Message"] as string)){
<script type="text/javascript">
    $(function () {
        $.showMessage({
            message: '@(Html.Raw(ViewData["Message"] as string))',
            beforeClose: function () {
                if ('@(Html.Raw(ViewData["Message"] as string))'.indexOf('sucesso') > 0)
                    location.href = '@Url.Content("~/usuario/list/")' ;
            } 
        });
    });
</script>
}
<script type="text/javascript">
    $(function () {
        setTimeout(function () {
            $("#carregarAvaliacoes").click();
            $("#IdCliente").bind('change', function () {
                $("#carregarAvaliacoes").click();
            });
        }, 10);
    });

    
</script>

}

<h3>Usuário</h3>

<div id="text1" class="span-24">
    @using (Html.BeginForm("Save", "Usuario", FormMethod.Post))
    {
    <input type="hidden" name="Id" id="Id" value="@Model.Id" />
    <div class="span-3">Cliente</div>
    <div class="span-8 last form">
        @Html.DropDownList("IdCliente",(IEnumerable<SelectListItem>)ViewData["Clientes"], new {style="width:587px"})
    </div>
    <div class="clear"></div>
    <div class="span-3">Nome</div>
    <div class="span-8 last form">
        <input type="text" name="Nome" value="@Model.Nome" style="width:585px;" maxlength="200" />
    </div>
    <div class="clear"></div>
    <div class="span-3">Email</div>
    <div class="span-8 last form">
        <input type="text" name="Email" value="@Model.Email" style="width:585px;" maxlength="200" />
    </div>
    <div class="clear"></div>
    <div class="span-3">Login</div>
    <div class="span-8 last form">
        <input type="text" name="Login" value="@Model.Login" style="width:585px;" maxlength="200" />
    </div>
    <div class="clear"></div>
    <div class="span-3">Senha</div>
    <div class="span-8 last form">
        <input type="text" name="Senha" value="@Model.Senha" style="width:585px;" maxlength="50" />
    </div>
    <div class="clear"></div>
    <div class="span-3">Tipo</div>
    <div class="span-8 last form">
        <select name="Tipo" style="width:587px;">
            <option value="U" @(Model.Tipo=="U"?"selected":"")>Usuário</option>
            <option value="G" @(Model.Tipo=="G"?"selected":"")>Gestor cliente</option>
            <option value="A" @(Model.Tipo=="A"?"selected":"")>Administrador sistema</option>
        </select>
    </div>
    <div class="clear"></div>
    <div class="span-3">Grupo</div>
    <div class="span-8 last form">
        @Html.DropDownList("IdGrupoUsuario", (IEnumerable<SelectListItem>)ViewData["Grupos"], new { style = "width:587px" })
    </div>
    <div class="clear"></div>
    <br />
    <div class="span-11">Avaliações do cliente</div>
    <div class="clear"></div>
    <div id="divAvaliacoes" class="span-18 last form" style="height:250px; overflow:scroll; overflow-x:hidden;"></div>
    <br />
    <br />
    <div class="span-18 last" style="text-align:right;">
        <input type="submit" name="Salvar" value="Salvar alterações" id="Salvar"/>
    </div>
    }
</div>
<input type="button" id="carregarAvaliacoes" value="Carregar avaliacoes" onclick="$('#divAvaliacoes').load('@Url.Content("~/usuario/ListAvaliacaoNoUsuario/")?idCliente=' + $('#IdCliente').val() + '&amp;idUsuario=@Model.Id');" style="display:none;" />